package com.github.ghsea.cc.util;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;

import org.springframework.beans.factory.FactoryBean;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

public class ScheduledExecutorServiceFactory implements FactoryBean<ScheduledExecutorService> {

	private ScheduledExecutorService executor;

	public ScheduledExecutorServiceFactory() {
		ThreadFactory tf = new ThreadFactoryBuilder().setNameFormat("com.github.ghsea.cc.util-thread-%d").build();
		executor = Executors.newScheduledThreadPool(1, tf);
	}

	public ScheduledExecutorService getObject() throws Exception {
		return executor;
	}

	public Class<?> getObjectType() {
		return ScheduledExecutorService.class;
	}

	public boolean isSingleton() {
		return true;
	}

}
